<template>
	<view class="">
		<no-data :list="goodsList"></no-data>
    <kristen-goods-list :goodsList="goodsList" :mpGoodsShow="'imgUpTxtDown'" @clickGood="clickGood"></kristen-goods-list>
	</view>
</template>
<style scoped>

</style>
<script>
	import KristenGoodsList from "@/uni_modules/goods-list/kristen-goodsList.vue";

  const $ = require('../../../utils/api.js');
	export default {
		props: {
			list: {
				type: Array,
				required: true
			},
			// offset 间距，单位为 px
			offset: {
				type: Number,
				default: 1.2
			},
			// 列表渲染的 key 的键名，值必须唯一，默认为 id
			idKey: {
				type: String,
				default: "id"
			},
			// 图片 src 的键名
			imageSrcKey: {
				type: String,
				default: "mainImg"
			},
      shopId:{
        type: Number,
      },
			// 列数
			cols: {
				type: Number,
				default: 2,
				validator: (num) => num >= 2
			},
			imageStyle: {
				type: Object
			},
			// 是否是单独的渲染图片的样子，只控制图片圆角而已
			single: {
				type: Boolean,
				default: false
			},
			cateIndex: {
				default: 0
			},
		},
		data() {
			return {
				goodsList: [],
			};
		},
		onLoad: function() {
		},
		watch: {
			cateIndex(newValue) {
				if(this.list.length <= 0){return;}
				this.goodsList = [];
				this.list.forEach((ele,index) => {
					if(ele.___index == newValue) {
						this.goodsList.push(ele);
					}
				})
				this.$refs.stylegoods.refresh();
			}
		},
		methods: {
      toGoodsDetail(){

      },
			clickGood(data) {
        //这里就不跳到店铺商品详情页面了
				$.go('/pagesA/shops/detail?id='+data.id+'&shopId='+this.shopId);
			},
			init() {
				this.goodsList = [];
				this.list.forEach((ele,index) => {
					if(ele.___index == this.cateIndex) {
						this.goodsList.push(ele);
					}
				})

			},
		},
		computed: {
			i18n() {
				return this.$t('goodsdetail')
			},
		},
		created() {
			this.init();
		},
		mounted() {},
		destroyed() {},
		components: {
      KristenGoodsList

    },
		onPullDownRefresh() {},
		onReachBottom() {}
	}
</script>
